package com.rongke.web.controller.cancertype;

import com.rongke.commons.JsonResp;
import com.rongke.model.CancerSpecies;
import com.rongke.service.CancerSpeciesService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @CancerSpeciesController
 * @癌症种类Controller
 * @version : Ver 1.0
 */
@RestController
@RequestMapping(value="/api/cancerSpecies")
@Transactional
public class CancerSpeciesController {
    private Logger log = Logger.getLogger(this.getClass());
    @Autowired
    private CancerSpeciesService cancerSpeciesService;

    /**
     * @添加癌症种类
     * @param cancerSpecies
     * @return 返回值JsonResp
     */
    @RequestMapping(value="/add", method = RequestMethod.POST)
    public JsonResp addCancerSpecies(@RequestBody CancerSpecies cancerSpecies){
        log.debug("添加癌症种类");
        cancerSpeciesService.insert(cancerSpecies);
        return JsonResp.ok(cancerSpecies);
    }

    /**
     * @修改癌症种类
     * @param cancerSpecies
     * @return 返回值JsonResp
     */
    @RequestMapping(value="/update", method = RequestMethod.POST)
    public JsonResp updateCancerSpecies(@RequestBody CancerSpecies cancerSpecies){
        log.debug("修改癌症种类");
        cancerSpeciesService.updateById(cancerSpecies);
        return JsonResp.ok(cancerSpecies);
    }
    /**
     * @根据id查找癌症种类
     * @param id
     * @return 返回值JsonResp
     */
    @RequestMapping(value="/selectOne", method = RequestMethod.GET)
    public JsonResp selectCancerSpecies(Long id){
        log.debug("查找癌症种类");
        CancerSpecies cancerSpecies = cancerSpeciesService.selectById(id);
        return JsonResp.ok(cancerSpecies);
    }
    /**
     * @根据id查找癌症种类
     * @param
     * @return 返回值JsonResp
     */
    @RequestMapping(value="/selectList", method = RequestMethod.GET)
    public JsonResp selectList(){
        log.debug("查找癌症种类");
        List<CancerSpecies> cancerSpecies = cancerSpeciesService.selectList(null);
        return JsonResp.ok(cancerSpecies);
    }

}
